#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string longestPalindrome(string s) {
        int begin = 0, maxlen = 1;
        for (int i = 0;i < s.size();i++)
        {
            int left = i - 1, right = i + 1;
            while (left >= 0 && right < s.size() && s[left] == s[right])
            {
                left--;
                right++;
                if (right - left - 1 > maxlen)
                {
                    begin = left + 1;
                    maxlen = right - left - 1;
                }
            }

            left = i, right = i + 1;
            while (left >= 0 && right < s.size() && s[left] == s[right])
            {
                left--;
                right++;
                if (right - left - 1 > maxlen)
                {
                    begin = left + 1;
                    maxlen = right - left - 1;
                }
            }
        }
        return s.substr(begin, maxlen);
    }
};